<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="main" />
        <title>Show Project ${fieldValue(bean:projectInstance, field:'name')}</title>
    </head>
    <body>
        <div class="undernav">
            <span class="menuButton"><g:link class="create" action="create">New Project</g:link></span>
        </div>
        <div class="body">

          <!-- display only if the current mode allows it -->
          <g:if test="${projectInstance.mode==2}">
            <g:btnMode mode="${session.mode}" currentView="show" currentController="project" idProject="${projectInstance.id}" showonlyfor="2"></g:btnMode>
          </g:if>
          <g:else>
            <div class="mode">
              <span style="font-weight:bold; padding-right:10px">
              <g:if test="${session.mode == null || session.mode.equalsIgnoreCase('sandbox')}">
                Sandbox mode
              </g:if>
              <g:else>
                Budget mode
              </g:else>
                </span>
            </div>
          </g:else>
          
          <g:javascript src="jquery.js" />
          <g:javascript src="jquery.livequery.js" />
          <g:javascript src="budget/editFigures.js" />
          <g:link class="hidden urlUpdateIncome" controller="project" action="updateIncome"></g:link>
          <input type="hidden" value="${fieldValue(bean:projectInstance, field:'id')}" id="projectId" />
            <h1>${fieldValue(bean:projectInstance, field:'name')}</h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="dialog">
                <table class="detailView">
                    <tbody>
                        <tr class="prop">
                            <td valign="top" class="name">Activity Id:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean:projectInstance, field:'activityId')}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name">Name:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean:projectInstance, field:'name')}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name">Description:</td>
                            
                            <td valign="top" class="value">${fieldValue(bean:projectInstance, field:'description')}</td>
                            
                        </tr>
                    <!--
                        <tr class="prop">
                            <td valign="top" class="name">Amount Of Hour:</td>
                            
                            <td  valign="top" style="text-align:left;" class="value">
                                <ul>
                                <g:each var="a" in="${projectInstance.amountOfHour}">
                                    <li><g:link controller="whoa" action="show" id="${a.id}">${a?.encodeAsHTML()}</g:link></li>
                                </g:each>
                                </ul>
                            </td>
                            
                        </tr>
                    -->
                        <tr class="prop">
                            <td valign="top" class="name">Area:</td>
                            
                            <td valign="top" class="value"><g:link controller="area" action="show" id="${projectInstance?.area?.id}">${projectInstance?.area?.encodeAsHTML()}</g:link></td>
                            
                        </tr>
                        <tr class="prop">
                            <td valign="top" class="name">Start Date:</td>

                            <td valign="top" class="value"><g:formatDate date="${projectInstance.startDate}" format="yyyy-MM-dd" /></td>

                        </tr>
                        <tr class="prop">
                            <td valign="top" class="name">End Date:</td>
                            
                            <td valign="top" class="value"><g:formatDate date="${projectInstance.endDate}" format="yyyy-MM-dd" /></td>
                            
                        </tr>
                    </tbody>
                </table>
               <div class="buttons">
                <g:form>
                    <input type="hidden" name="id" value="${projectInstance?.id}" />
                    <span class="button"><g:actionSubmit class="edit" value="Edit" /></span>
                    <span class="button"><g:actionSubmit class="delete" onclick="return confirm('You are going to delete the entire project. Are you sure?');" value="Delete" /></span>
                </g:form>
               </div>

              <div class="budgetView">
                <h2>Income and Expenditures</h2>
                <table class="">
                    <tbody>
                        <tr class="prop">
                            <td valign="top" class="name">Known Income :</td>
                            <td valign="top" class="value"><span id="knownIncome" class="incomeFigures">${projectInstance?.currentBudget()?.knownTotalIncome}</span></td>
                        </tr>
                        <tr class="prop">
                            <td valign="top" class="name">Expected Income :</td>
                            <td valign="top" class="value"><span id="expectedIncome" class="incomeFigures">${projectInstance?.currentBudget()?.expectedTotalIncome}</span></td>
                        </tr>
                    </tbody>
                </table>
              </div>
              <div class="membersView">
                  <h2>Members</h2>
                  <table>
                    <tbody>
                      <tr>
                        <th>Name</th>
                        <th>Salary</th>
                        <th>Hours in project</th>
                        <th>Cost</th>
                      </tr>
                      <g:each var="m" in="${projectInstance.amountOfHour}">
                        <g:if test="${(session.mode != null && session.mode.equalsIgnoreCase('budget') && m?.mode==0) ||((session.mode==null||session.mode.equalsIgnoreCase('sandbox')) && m?.mode==1) || m?.mode==2}">
                          <tr>
                            <td><g:link action="show" controller="employee" id="${m?.member?.id}">${m?.member?.firstName} ${m?.member?.lastName}</g:link></td>
                            <td><g:formatNumber number="${m?.member?.salary}" format="SEK ##,##0" /></td>
                            <td>${m?.hours}</td>
                            <td>${m?.calculateCost()}</td>
                          </tr>
                        </g:if>
                      </g:each>
                    </tbody>
                  </table>
                </div>
            </div>
            <div class="buttons">
                <g:form>
                    <input type="hidden" name="id" value="${projectInstance?.id}" />
                    <span class="button"><g:actionSubmit action ="add_employee" class="add_employee"  value="Add Employee" /></span>
                    <g:if test="${numberOfEmployees > 0}">
                      <span class="button"><g:actionSubmit action ="delete_employee" class="delete_employee"  value="Remove Employee" /></span>
                    </g:if>
                 </g:form>
            </div>
        </div>
    </body>
</html>
